package com.yunhuajinfu.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.wheel.test.OnWheelScrollListener;
import android.wheel.test.WheelView;
import android.wheel.test.adapter.AbstractWheelTextAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.lzy.okhttputils.model.HttpParams;
import com.yunhuajinfu.R;
import com.yunhuajinfu.base.BaseActivity;
import com.yunhuajinfu.entity.Pages;
import com.yunhuajinfu.http.HttpCallBack;
import com.yunhuajinfu.http.HttpUtils;
import com.yunhuajinfu.mian.Config;
import com.yunhuajinfu.nbpullToRefresh.BaseRefreshListener;
import com.yunhuajinfu.nbpullToRefresh.PullToRefreshLayout;
import com.yunhuajinfu.response.TradingRecordRes;
import com.yunhuajinfu.tool.StatusBarUtil;
import com.yunhuajinfu.tool.Tool;
import com.yunhuajinfu.view.TitleBar;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 个人中心  交易记录
 */
public class TradingRecordActivity extends BaseActivity implements BaseRefreshListener{
    @Bind(R.id.titlebar)
    TitleBar titlebar;
    @Bind(R.id.tv_start_day)
    TextView tvStartDay;
    @Bind(R.id.tv_end_day)
    TextView tvEndDay;
    @Bind(R.id.listview)
    ListView listView;
    @Bind(R.id.mPullToRefreshLayout)
    PullToRefreshLayout mPullToRefreshLayout;
    @Bind(R.id.iv_search)
    ImageView msearch;
    @Bind(R.id.mViewNeedOffset)
    LinearLayout mViewNeedOffset;
    //
    private TradingRecordAdapter tradingRecordAdapter;
    //
    private int pageNum = 1;
    private String beginTime;
    private String endTime;
    private boolean falg=true;
    ArrayList<Pages> page=new ArrayList<>();
    //
    private View startView, endView;
    private WheelView startYearView, startMonthView, startDayView;
    private WheelView endYearView, endMonthView, endDayView;
    private Button startDone, endDone;
    private String[] years, months, days;   //放入年  月  日
    private String startYear = "", startMonth = "", startDay = "", endYear = "", endMonth = "", endDay = "";
    private Dialog startDialog, endDialog;
    private List<String> startYearList, startMonthList, startDayList;
    private List<String> endYearList, endMonthList, endDayList;
    private YearAdapter startYearAdapter, endYearAdapter;
    private MonthAdapter startMonthAdapter, endMonthAdapter;
    private DayAdapter startDayAdapter, endDayAdapter;
    private final int MIN_YEAR = 1980;
    private int max_Year;
    private SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
    private SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
    private SimpleDateFormat dayFormat = new SimpleDateFormat("dd");
    private int startYearIndex, startMonthIndex, startDayIndex;
    private int endYearIndex, endMonthIndex, endDayIndex;
    private Resources res;
    Date date = new Date();

    //

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_trading_record);
        StatusBarUtil.setTranslucentForImageView(this,0,mViewNeedOffset);
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initTitle() {
        titlebar.setTitleBar(R.drawable.back_selector, "交易记录", 0);
    }

    @Override
    protected void initView() {
        mPullToRefreshLayout.setRefreshListener(this);
        tradingRecordAdapter = new TradingRecordAdapter(TradingRecordActivity.this, page);
        listView.setAdapter(tradingRecordAdapter);

        //日历控件
        startView = LayoutInflater.from(this).inflate(R.layout.wheel_view, null);
        startYearView = (WheelView) startView.findViewById(R.id.year);
        startMonthView = (WheelView) startView.findViewById(R.id.month);
        startDayView = (WheelView) startView.findViewById(R.id.day);
        startDone = (Button) startView.findViewById(R.id.done);
        TextView textView1 = (TextView) startView.findViewById(R.id.whell_view_textview);
        textView1.setText("起始日期：");

        endView = LayoutInflater.from(this).inflate(R.layout.wheel_view, null);
        endYearView = (WheelView) endView.findViewById(R.id.year);
        endMonthView = (WheelView) endView.findViewById(R.id.month);
        endDayView = (WheelView) endView.findViewById(R.id.day);
        endDone = (Button) endView.findViewById(R.id.done);
        TextView textView2 = (TextView) endView.findViewById(R.id.whell_view_textview);
        textView2.setText("结束日期：");

        res = getResources();
        months = res.getStringArray(R.array.months);
        days = res.getStringArray(R.array.days_31);

        //获取当前的年
        String year = yearFormat.format(date);
        max_Year = Integer.parseInt(year);
        startYearList = new ArrayList<String>();
        for (int i = MIN_YEAR; i <= max_Year; i++) {
            startYearList.add(i + "");
        }
        startMonthList = Arrays.asList(months);
        startDayList = Arrays.asList(days);
        endYearList = startYearList;
        endMonthList = startMonthList;
        endDayList = startDayList;

        startYearAdapter = new YearAdapter(this, startYearList);
        startMonthAdapter = new MonthAdapter(this, startMonthList);
        startDayAdapter = new DayAdapter(this, startDayList);
        startYearView.setViewAdapter(startYearAdapter);
        startMonthView.setViewAdapter(startMonthAdapter);
        startDayView.setViewAdapter(startDayAdapter);

        endYearAdapter = new YearAdapter(this, endYearList);
        endMonthAdapter = new MonthAdapter(this, endMonthList);
        endDayAdapter = new DayAdapter(this, endDayList);
        endYearView.setViewAdapter(endYearAdapter);
        endMonthView.setViewAdapter(endMonthAdapter);
        endDayView.setViewAdapter(endDayAdapter);

        startDialog = new Dialog(this);
        startDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        startDialog.setContentView(startView);
        Window startWindow = startDialog.getWindow();
        startWindow.setGravity(Gravity.BOTTOM);
        startWindow.setLayout(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        startWindow.setWindowAnimations(R.style.view_animation);

        endDialog = new Dialog(this);
        endDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        endDialog.setContentView(endView);
        Window endWindow = endDialog.getWindow();
        endWindow.setGravity(Gravity.BOTTOM);
        endWindow.setLayout(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        endWindow.setWindowAnimations(R.style.view_animation);

        //
        startYearView.addScrollingListener(new OnWheelScrollListener() {
            @Override
            public void onScrollingStarted(WheelView wheel) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onScrollingFinished(WheelView wheel) {
                // TODO Auto-generated method stub
                startYearIndex = wheel.getCurrentItem();
                String year = (String) startYearAdapter.getItemText(startYearIndex);
                String month = (String) startMonthAdapter.getItemText(startMonthIndex);
                if (Integer.parseInt(month) == 2) {
                    if (isLeapYear(year)) {
                        //29 闰年2月29天
                        if (startDayAdapter.list.size() != 29) {
                            startDayList = Arrays.asList(res.getStringArray(R.array.days_29));
                            startDayAdapter = new DayAdapter(TradingRecordActivity.this, startDayList);
                            startDayView.setViewAdapter(startDayAdapter);
                            if (startDayIndex > 28) {
                                startDayView.setCurrentItem(0);
                                startDayIndex = 0;
                            } else {
                                startDayView.setCurrentItem(startDayIndex);
                            }
                        }
                    } else {
                        //28 非闰年2月28天
                        if (startDayAdapter.list.size() != 28) {
                            startDayList = Arrays.asList(res.getStringArray(R.array.days_28));
                            startDayAdapter = new DayAdapter(TradingRecordActivity.this, startDayList);
                            startDayView.setViewAdapter(startDayAdapter);
                            if (startDayIndex > 27) {
                                startDayView.setCurrentItem(0);
                                startDayIndex = 0;
                            } else {
                                startDayView.setCurrentItem(startDayIndex);
                            }
                        }
                    }
                }
            }
        });


        startMonthView.addScrollingListener(new OnWheelScrollListener() {
            @Override
            public void onScrollingStarted(WheelView wheel) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onScrollingFinished(WheelView wheel) {
                // TODO Auto-generated method stub
                startMonthIndex = wheel.getCurrentItem();
                String year = (String) startYearAdapter.getItemText(startYearIndex);
                String month = (String) startMonthAdapter.getItemText(startMonthIndex);
                int i = Integer.parseInt(month);
                if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
                    //31
                    if (startDayAdapter.list.size() != 31) {
                        startDayList = Arrays.asList(res.getStringArray(R.array.days_31));
                        startDayAdapter = new DayAdapter(TradingRecordActivity.this, startDayList);
                        startDayView.setViewAdapter(startDayAdapter);
                        startDayView.setCurrentItem(startDayIndex);
                    }
                } else if (i == 2) {
                    if (isLeapYear(year)) {
                        //29 闂板勾2鏈?9澶?
                        if (startDayAdapter.list.size() != 29) {
                            startDayList = Arrays.asList(res.getStringArray(R.array.days_29));
                            startDayAdapter = new DayAdapter(TradingRecordActivity.this, startDayList);
                            startDayView.setViewAdapter(startDayAdapter);
                            if (startDayIndex > 28) {
                                startDayView.setCurrentItem(0);
                                startDayIndex = 0;
                            } else {
                                startDayView.setCurrentItem(startDayIndex);
                            }
                        }
                    } else {
                        //28 闈為棸骞?鏈?8澶?
                        if (startDayAdapter.list.size() != 28) {
                            startDayList = Arrays.asList(res.getStringArray(R.array.days_28));
                            startDayAdapter = new DayAdapter(TradingRecordActivity.this, startDayList);
                            startDayView.setViewAdapter(startDayAdapter);
                            if (startDayIndex > 27) {
                                startDayView.setCurrentItem(0);
                                startDayIndex = 0;
                            } else {
                                startDayView.setCurrentItem(startDayIndex);
                            }
                        }
                    }
                } else {
                    //30
                    if (startDayAdapter.list.size() != 30) {
                        startDayList = Arrays.asList(res.getStringArray(R.array.days_30));
                        startDayAdapter = new DayAdapter(TradingRecordActivity.this, startDayList);
                        startDayView.setViewAdapter(startDayAdapter);
                        if (startDayIndex > 29) {
                            startDayView.setCurrentItem(0);
                            startDayIndex = 0;
                        } else {
                            startDayView.setCurrentItem(startDayIndex);
                        }
                    }
                }
            }
        });
        startDayView.addScrollingListener(new OnWheelScrollListener() {
            @Override
            public void onScrollingStarted(WheelView wheel) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onScrollingFinished(WheelView wheel) {
                // TODO Auto-generated method stub
                startDayIndex = wheel.getCurrentItem();
            }
        });

        endYearView.addScrollingListener(new OnWheelScrollListener() {
            @Override
            public void onScrollingStarted(WheelView wheel) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onScrollingFinished(WheelView wheel) {
                // TODO Auto-generated method stub
                endYearIndex = wheel.getCurrentItem();
                String year = (String) endYearAdapter.getItemText(endYearIndex);
                String month = (String) endMonthAdapter.getItemText(endMonthIndex);
                if (Integer.parseInt(month) == 2) {
                    if (isLeapYear(year)) {
                        //29
                        if (endDayAdapter.list.size() != 29) {
                            endDayList = Arrays.asList(res.getStringArray(R.array.days_29));
                            endDayAdapter = new DayAdapter(TradingRecordActivity.this, endDayList);
                            endDayView.setViewAdapter(endDayAdapter);
                            if (endDayIndex > 28) {
                                endDayView.setCurrentItem(0);
                                endDayIndex = 0;
                            } else {
                                endDayView.setCurrentItem(endDayIndex);
                            }
                        }
                    } else {
                        //28
                        if (endDayAdapter.list.size() != 28) {
                            endDayList = Arrays.asList(res.getStringArray(R.array.days_28));
                            endDayAdapter = new DayAdapter(TradingRecordActivity.this, endDayList);
                            endDayView.setViewAdapter(endDayAdapter);
                            if (endDayIndex > 27) {
                                endDayView.setCurrentItem(0);
                                endDayIndex = 0;
                            } else {
                                endDayView.setCurrentItem(endDayIndex);
                            }
                        }
                    }
                }
            }
        });
        endMonthView.addScrollingListener(new OnWheelScrollListener() {
            @Override
            public void onScrollingStarted(WheelView wheel) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onScrollingFinished(WheelView wheel) {
                // TODO Auto-generated method stub
                endMonthIndex = wheel.getCurrentItem();
                String year = (String) endYearAdapter.getItemText(endYearIndex);
                String month = (String) endMonthAdapter.getItemText(endMonthIndex);
                int i = Integer.parseInt(month);
                if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
                    //31
                    if (endDayAdapter.list.size() != 31) {
                        endDayList = Arrays.asList(res.getStringArray(R.array.days_31));
                        endDayAdapter = new DayAdapter(TradingRecordActivity.this, endDayList);
                        endDayView.setViewAdapter(endDayAdapter);
                        endDayView.setCurrentItem(endDayIndex);
                    }
                } else if (i == 2) {
                    if (isLeapYear(year)) {
                        //29
                        if (endDayAdapter.list.size() != 29) {
                            endDayList = Arrays.asList(res.getStringArray(R.array.days_29));
                            endDayAdapter = new DayAdapter(TradingRecordActivity.this, endDayList);
                            endDayView.setViewAdapter(endDayAdapter);
                            if (endDayIndex > 28) {
                                endDayView.setCurrentItem(0);
                                endDayIndex = 0;
                            } else {
                                endDayView.setCurrentItem(endDayIndex);
                            }
                        }
                    } else {
                        //28
                        if (endDayAdapter.list.size() != 28) {
                            endDayList = Arrays.asList(res.getStringArray(R.array.days_28));
                            endDayAdapter = new DayAdapter(TradingRecordActivity.this, endDayList);
                            endDayView.setViewAdapter(endDayAdapter);
                            if (endDayIndex > 27) {
                                endDayView.setCurrentItem(0);
                                endDayIndex = 0;
                            } else {
                                endDayView.setCurrentItem(endDayIndex);
                            }
                        }
                    }
                } else {
                    //30
                    if (endDayAdapter.list.size() != 30) {
                        endDayList = Arrays.asList(res.getStringArray(R.array.days_30));
                        endDayAdapter = new DayAdapter(TradingRecordActivity.this, endDayList);
                        endDayView.setViewAdapter(endDayAdapter);
                        if (endDayIndex > 29) {
                            endDayView.setCurrentItem(0);
                            endDayIndex = 0;
                        } else {
                            endDayView.setCurrentItem(endDayIndex);
                        }
                    }
                }
            }
        });
        endDayView.addScrollingListener(new OnWheelScrollListener() {
            @Override
            public void onScrollingStarted(WheelView wheel) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onScrollingFinished(WheelView wheel) {
                // TODO Auto-generated method stub
                endDayIndex = wheel.getCurrentItem();
            }
        });


        //
        startDone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                startDialog.dismiss();
                startYear = (String) startYearAdapter.getItemText(startYearIndex);
                startMonth = (String) startMonthAdapter.getItemText(startMonthIndex);
                startDay = (String) startDayAdapter.getItemText(startDayIndex);
                tvStartDay.setText(startYear + "-" + startMonth + "-" + startDay);
            }
        });
        endDone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                endDialog.dismiss();
                endYear = (String) endYearAdapter.getItemText(endYearIndex);
                endMonth = (String) endMonthAdapter.getItemText(endMonthIndex);
                endDay = (String) endDayAdapter.getItemText(endDayIndex);
                tvEndDay.setText(endYear + "-" + endMonth + "-" + endDay);
            }
        });


    }

    @Override
    protected void setData() {


        getCapitalRecord(beginTime, endTime);

    }


    /**
     * 判断是否是闰年
     */
    public static boolean isLeapYear(String str) {
        int year = Integer.parseInt(str);
        return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
    }


    @OnClick({R.id.titlebar_iv_back, R.id.titlebar_iv_rignt_img, R.id.tv_start_day, R.id.tv_end_day, R.id.iv_search})
    @Override
    public void widgetClick(View v) {

        switch (v.getId()) {

            case R.id.titlebar_iv_back:

                finish();


                break;

            case R.id.titlebar_iv_rignt_img:

                Toast.makeText(this, "dian", Toast.LENGTH_SHORT).show();


                break;


            case R.id.tv_start_day:

//                Toast.makeText(this, "sdf", Toast.LENGTH_SHORT).show();


                startBtn();


                break;


            case R.id.tv_end_day:

//                Toast.makeText(this, "kllkj", Toast.LENGTH_SHORT).show();

                endBtn();

                break;


            case R.id.iv_search:
                beginTime = tvStartDay.getText().toString().trim();
                endTime = tvEndDay.getText().toString().trim();
                if (TextUtils.isEmpty(beginTime)) {
                    Toast.makeText(TradingRecordActivity.this, "开始日期不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }else if (TextUtils.isEmpty(endTime)) {
                    Toast.makeText(TradingRecordActivity.this, "结束日期不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }else if(!Tool.DateCompare(endTime,beginTime)){
                    Toast.makeText(TradingRecordActivity.this, "查询结束日期不能小于查询开始日期", Toast.LENGTH_SHORT).show();
                    return;
                }
                else {
                    //调用接口拉数据
                    pageNum=1;
                    falg=true;
                    getCapitalRecord(beginTime,endTime);
                }

                break;

            default:
        }


    }

    private void endBtn() {


        if ("".equals(endYear)) {
            endYear = max_Year + "";
            endMonth = monthFormat.format(date);
            endDay = dayFormat.format(date);
        }
        endYearIndex = endYearList.indexOf(endYear);
        endMonthIndex = endMonthList.indexOf(endMonth);
        endDayIndex = endDayList.indexOf(endDay);
        if (endYearIndex == -1) {
            endYearIndex = 0;
        }
        if (endMonthIndex == -1) {
            endMonthIndex = 0;
        }
        if (endDayIndex == -1) {
            endDayIndex = 0;
        }
        endYearView.setCurrentItem(endYearIndex);
        endMonthView.setCurrentItem(endMonthIndex);
        endDayView.setCurrentItem(endDayIndex);
        endDialog.show();


    }

    private void startBtn() {

        if ("".equals(startYear)) {
            startYear = max_Year + "";
            startMonth = monthFormat.format(date);
            startDay = dayFormat.format(date);
        }
        startYearIndex = startYearList.indexOf(startYear);
        startMonthIndex = startMonthList.indexOf(startMonth);
        startDayIndex = startDayList.indexOf(startDay);
        if (startYearIndex == -1) {
            startYearIndex = 0;
        }
        if (startMonthIndex == -1) {
            startMonthIndex = 0;
        }
        if (startDayIndex == -1) {
            startDayIndex = 0;
        }
        startYearView.setCurrentItem(startYearIndex);
        startMonthView.setCurrentItem(startMonthIndex);
        startDayView.setCurrentItem(startDayIndex);
        startDialog.show();


    }




    class YearAdapter extends AbstractWheelTextAdapter {
        /**
         * Constructor
         */
        public List<String> list;

        protected YearAdapter(Context context, List<String> list) {
            super(context, R.layout.wheel_view_layout, NO_RESOURCE);
            this.list = list;
        }

        @Override
        public View getItem(int index, View cachedView, ViewGroup parent) {
            View view = super.getItem(index, cachedView, parent);

            TextView textCity = (TextView) view.findViewById(R.id.textView);
            textCity.setText(list.get(index));
            return view;
        }

        public int getItemsCount() {
            return list.size();
        }

        @Override
        protected CharSequence getItemText(int index) {
            return list.get(index);
        }
    }

    class MonthAdapter extends AbstractWheelTextAdapter {
        /**
         * Constructor
         */
        public List<String> list;

        protected MonthAdapter(Context context, List<String> list) {
            super(context, R.layout.wheel_view_layout, NO_RESOURCE);
            this.list = list;
        }

        @Override
        public View getItem(int index, View cachedView, ViewGroup parent) {
            View view = super.getItem(index, cachedView, parent);

            TextView textCity = (TextView) view.findViewById(R.id.textView);
            textCity.setText(list.get(index));
            return view;
        }

        public int getItemsCount() {
            return list.size();
        }

        @Override
        protected CharSequence getItemText(int index) {
            return list.get(index);
        }
    }

    class DayAdapter extends AbstractWheelTextAdapter {
        /**
         * Constructor
         */
        public List<String> list;

        protected DayAdapter(Context context, List<String> list) {
            super(context, R.layout.wheel_view_layout, NO_RESOURCE);
            this.list = list;
        }

        @Override
        public View getItem(int index, View cachedView, ViewGroup parent) {
            View view = super.getItem(index, cachedView, parent);

            TextView textCity = (TextView) view.findViewById(R.id.textView);
            textCity.setText(list.get(index));
            return view;
        }

        public int getItemsCount() {
            return list.size();
        }

        @Override
        protected CharSequence getItemText(int index) {
            return list.get(index);
        }
    }


    /**
     * 交易记录适配器
     */

    public class TradingRecordAdapter extends BaseAdapter {

        private Context context;
        List<Pages> infos;
        private LayoutInflater inflater;


        public TradingRecordAdapter(Context context, List<Pages> infos) {
            this.context = context;
            this.infos = infos;
            inflater = LayoutInflater.from(context);

        }

        public void UpdatedAdapter(List<Pages> infos) {
            this.infos = infos;
            notifyDataSetChanged();
        }


        @Override
        public int getCount() {
            return infos.size();
        }

        @Override
        public Object getItem(int position) {
            return infos.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder viewHolder = null;
            if (viewHolder == null) {
                viewHolder = new ViewHolder();

                convertView = inflater.inflate(R.layout.tradingrecord_item, null);

                viewHolder.tv_logRemark= (TextView) convertView.findViewById(R.id.tv_logRemark);
                viewHolder.tv_transTime=(TextView) convertView.findViewById(R.id.tv_transTime);
                viewHolder.tv_transType=(TextView) convertView.findViewById(R.id.tv_transType);
                viewHolder.tv_TransAmount= (TextView) convertView.findViewById(R.id.tv_TransAmount);

                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }

            Pages info = infos.get(position);
            viewHolder.tv_logRemark.setText("备注 : "+info.getLogRemark());
            viewHolder.tv_transTime.setText(info.getTransTime());
            viewHolder.tv_transType.setText("状态 : "+info.getTransType());
            viewHolder.tv_TransAmount.setText("金额 :"+info.getTransAmount()+"(元)");



            return convertView;
        }
    }


    public final class ViewHolder {

        TextView tv_logRemark;
        TextView tv_transType;
        TextView tv_transTime;
        TextView tv_TransAmount;


    }


    /**
     * 获取交易记录
     */
    private void getCapitalRecord(String beginTime, String endTime) {
        final HttpParams params = new HttpParams();
        params.put("pageNum", pageNum + "");
        params.put("beginTime", beginTime);
        params.put("endTime", endTime);

        HttpUtils.post(Config.CAPITALRECORD, params, new HttpCallBack(TradingRecordActivity.this, "加载中...") {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {

                if (null != result) {
                    try {
                        TradingRecordRes res = new TradingRecordRes(new JSONObject(result.toString()));
//
                        if(falg==true){
                            if(null!=res && res.getPage().size()>0){
                                page.clear();
                                page=res.getPage();
                            }else {
                                page.clear();
                                Toast.makeText(TradingRecordActivity.this, "无数据", Toast.LENGTH_SHORT).show();
                            }

                        }else{
                            if(!res.getCurrentPage().equals(res.getTotalPage())){
                                page.addAll(res.getPage());
                            }else{
                                if(res.getPage().size()>0){
                                    page.addAll(res.getPage());
                                }else {
                                    Toast.makeText(TradingRecordActivity.this, "无更多加载数据", Toast.LENGTH_SHORT).show();

                                }
                            }
                        }

                        tradingRecordAdapter.UpdatedAdapter(page);
                        //释放
                        onLoad();


                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }


            }

            @Override
            public void onError(String code, String message) {
                //释放
                onLoad();
                Toast.makeText(TradingRecordActivity.this, message, Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public void refresh() {
        pageNum=1;
        falg=true;
        getCapitalRecord(beginTime, endTime);

    }

    @Override
    public void loadMore() {

        falg=false;
        pageNum++;
        getCapitalRecord(beginTime, endTime);
    }


    private void onLoad() {
       mPullToRefreshLayout.finishRefresh();
        mPullToRefreshLayout.finishLoadMore();
    }

}
